<template>
	<view class="mainbgc">
		<u-navbar :placeholder="true">
			<view class="ss flexleft" slot="left" @click="jumpdetail('/pages/shopping/shangpinlb','')">
				<image src="@/static/images/sy_slices/search.png" mode="" class="search"></image>
				<input type="text" placeholder="请输入搜索内容" disabled="">
			</view>
		</u-navbar>
		<view class="flexleft">
			<scroll-view scroll-y="true" class="scroll-Yleft">
				<!-- <view class="itemli-boxf">
					<view class="">推荐推荐</view>
				</view> -->
				<view :class="item.id==leftlistid?'itemli-boxf':'itemli-box'" v-for="item in leftlist" :key="item.id" @click="changeleft(item)">
					<view :class="item.id==leftlistid?'itemli-contentf':'itemli-content'">{{item.name}}</view>
				</view>
			</scroll-view>
			<scroll-view scroll-y="true" class="scroll-Yright ffffff mainpadding">
				<!-- 推荐 -->
				<view v-if="leftlistid==''" >
					<view class="" v-if="hotfllist.length">
						<view class="titletext">分类推荐</view>
						<view class="flexleft flex_wrap">
							<view class="flexcolumn itemfl margin_top" v-for="item in hotfllist" :key="item.id" @click="jumpdetail('/pages/shopping/shangpinlb?id=',item.id)">
								<view class="flimg">
									<!-- <image :src="item.image_text" mode=""></image> -->
									<image :src="item.image_text" mode=""></image>
								</view>
								<view class="strongtext" style="margin-top: 10rpx;">{{item.name}}</view>
							</view>
						</view>
					</view>
					<view class="" v-if="list.data.length">
						<view class="titletext margin_top">热门商品</view>
						<view class="flexleft margin_top" v-for="item in list.data" :key="item.id" @click="jumpdetail('/pages/shopping/shangpinxq?id=',item.id)">
							<view class="leftimg margin_right">
								<image :src="item.image_text" mode=""></image>
							</view>
							<view class="flexstartclom">
								<view class="strongtext goodsnote lianghang">{{item.title}}</view>
								<view class="price">{{item.price}}</view>
							</view>
						</view>
					</view>
				</view>
				<!-- 其他 -->
				<view class="" v-else>
					<view v-for="item in rightlist" :key="item.id">
						<view class="flexbetween margin_top" @click="jumpdetail('/pages/shopping/shangpinlb?id=',item.id)">
							<view class="titletext">{{item.name}}</view>
							<view class="lookall flexleft">查看全部<u-icon name="arrow-right" color="#228DFF" size="13">
								</u-icon>
							</view>
						</view>
						<view class="flexleft flex_wrap">
							<view class="flexcolumn itemfl margin_top" v-for="ite in item.childlist" :key="ite.id"  @click="jumpdetail('/pages/shopping/shangpinlb?id=',ite.id)">
								<view class="flimg">
									<image :src="ite.image_text" mode=""></image>
								</view>
								<view class="strongtext" style="margin-top: 10rpx;">{{ite.name}}</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				leftlist: [],//左侧列表
				rightlist: [],//右侧内容
				leftlistid:"",//左侧列表id
				category_id: "", //产品分类id
				hotfllist:[],//热门分类内容
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onLoad() {
			this.init()
			this.getfl()
		},
		onShow() {
		},
		onShareAppMessage: function(options) {
			return {
				title: '物流托盘包装交易平台',
				imageUrl: '',
				path: '/pages/index/index?invite_code=' + uni.getStorageSync("invite_code")
			}
		},
		onShareTimeline: function() {
			return {
				title: '物流托盘包装交易平台',
				imageUrl: '',
				path: '/pages/index/index?invite_code=' + uni.getStorageSync("invite_code")
			}
		},
		methods: {
			jumpdetail(urls, id) {
				uni.navigateTo({
					url: urls + id
				})
			},
			changeleft(item){
				this.leftlistid = item.id
				if(item.id!=""){
					this.rightlist = item.childlist
				}else{
					this.rightlist = []
				}
			},
			// 获取行业咨询列表
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/api/goods/goodsList', 'GET', {
					page: page || 1,
					limit: _this.limit,
					hot_status:1,
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
			
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			getfl() {
				httpRequest.request('/api/goods/categoryList', 'GET', {
					hot_status: 0,
					category_type:1
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.leftlist = res.data
						this.gethotfl()
					}
				})
			},
			gethotfl(){
				httpRequest.request('/api/goods/categoryList', 'GET', {
					hot_status: 1,
					category_type:1
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let flag = false
						this.leftlist.forEach(item=>{
							if(item.name=='推荐'){
								flag = true
							}
						})
						if(!flag){
							this.leftlist.unshift({
								name:"推荐",
								id:""
							})
						}
						this.hotfllist = res.data
						
					}
				})
			},
			doSearch() {
				uni.navigateTo({
					url: "/pages/shopping/shangpinlb"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.ss {
		background-color: #f3f3f3;
		border-radius: 60rpx 60rpx 60rpx 60rpx;
		padding: 10rpx 18rpx;
	}

	.search {
		width: 27rpx;
		height: 27rpx;
		margin-right: 30rpx;
	}

	.scroll-Yleft {
		height: calc(100vh - 230rpx);
		width: 190rpx;
	}

	.scroll-Yright {
		height: calc(100vh - 230rpx);
		width: calc(100vw - 190rpx);

	}

	.itemli-boxf {
		padding: 20rpx 15rpx;
		background-color: #fff;
	}

	.itemli-box {
		padding: 20rpx 15rpx;
		background-color: #F9F9F8;
	}

	.itemli-contentf {
		padding: 0 15rpx;
		text-align: center;
		box-sizing: border-box;
		border-left: 2rpx solid #228DFF;
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #228DFF;
		// width: 160rpx;
		// overflow: hidden;
		// text-overflow: ellipsis;
		// white-space: nowrap;
	}

	.itemli-content {
		padding: 0 15rpx;
		text-align: center;
		box-sizing: border-box;
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #666666;
		// width: 160rpx;
		// overflow: hidden;
		// text-overflow: ellipsis;
		// white-space: nowrap;
	}

	.itemfl {
		width: 45%;

	}



	.flimg {
		width: 120rpx;
		height: 120rpx;
		border-radius: 10rpx;

		image {
			width: 120rpx;
			height: 120rpx;
			border-radius: 10rpx;
		}
	}

	.leftimg {
		width: 180rpx;
		height: 180rpx;
		border-radius: 10rpx;
		flex: 2;

		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}

	.goodsnote {
		height: 80rpx;
	}

	.flexstartclom {
		flex: 3;
	}

	.price {
		font-size: 30rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FD463E;
		margin-top: 40rpx;
	}

	.lookall {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #228DFF;
	}
</style>
